Let's wrap up this Deep Learning by taking a a quick look at the effectiveness of Neural Nets!
We'll use the Bank Authentication Data Set from the UCI repository.
The data consists of 5 columns:
Where class indicates whether or not a Bank Note was authentic.
This sort of task is perfectly suited for Neural Networks and Deep Learning! Just follow the instructions below to get started!
In [1]:
In [2]:
Check the head of the Data
In [3]:
Out[3]:
In [4]:
Create a Countplot of the Classes (Authentic 1 vs Fake 0)
In [5]:
Out[5]:
Create a PairPlot of the Data with Seaborn, set Hue to Class
In [6]:
Out[6]:
In [7]:
Create a StandardScaler() object called scaler.
In [8]:
Fit scaler to the features.
In [9]:
Out[9]:
Use the .transform() method to transform the features to a scaled version.
In [10]:
Convert the scaled features to a dataframe and check the head of this dataframe to make sure the scaling worked.
In [11]:
Out[11]:
In [12]:
In [13]:
Use SciKit Learn to create training and testing sets of the data as we've done in previous lectures:
In [14]:
In [15]:
In [16]:
Create a list of feature column objects using tf.feature.numeric_column() as we did in the lecture
In [17]:
Out[17]:
In [18]:
In [19]:
Create an object called classifier which is a DNNClassifier from learn. Set it to have 2 classes and a [10,20,10] hidden unit layer structure:
In [20]:
Now create a tf.estimator.pandas_input_fn that takes in your X_train, y_train, batch_size and set shuffle=True. You can play around with the batch_size parameter if you want, but let's start by setting it to 20 since our data isn't very big.
In [21]:
Now train classifier to the input function. Use steps=500. You can play around with these values if you want!
Note: Ignore any warnings you get, they won't effect your output
In [22]:
Out[22]:
Create another pandas_input_fn that takes in the X_test data for x. Remember this one won't need any y_test info since we will be using this for the network to create its own predictions. Set shuffle=False since we don't need to shuffle for predictions.
In [23]:
Use the predict method from the classifier model to create predictions from X_test
In [24]:
In [25]:
Out[25]:
In [26]:
Now create a classification report and a Confusion Matrix. Does anything stand out to you?
In [27]:
In [28]:
In [29]:
In [30]:
In [31]:
In [32]:
Out[32]:
In [33]:
In [34]:
In [35]:
It should have also done very well, possibly perfect! Hopefully you have seen the power of DNN!